﻿{include file="../application/admin/view/common/header.html" /}

        <!--main content start-->
        <section class="main-content">
            <!--start page content-->
            <div class="row">
               
                <div class="col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-body">
                            <div class="tabs">
                                <!-- Nav tabs -->
                                <ul class="list-inline tabs-nav" role="tablist">
                                    <li all="1" role="presentation" class="active"><a href="#company" aria-controls="company" role="tab" data-toggle="tab" aria-expanded="true">企业名单</a></li>
                                    <li all="2" role="presentation" class=""><a href="#organization" aria-controls="organization" role="tab" data-toggle="tab" aria-expanded="false">机构名单</a></li>
                                    <li all="3" role="presentation" class=""><a href="#agent" aria-controls="agent" role="tab" data-toggle="tab" aria-expanded="false">专利代理人名单</a></li>
                                </ul>
								<input type="hidden" id="type" />
                                <!-- Tab panes -->
                                <div class="tab-content">
                                    <div role="tabpanel" class="tab-pane active" id="company">
                                        <div class="row">               
                                            <div class="col-md-12">
                                                <div class="panel panel-default collapsed">
                                                    <div class="panel-heading"> 
                                                        <a class="btn btn-blue ui-w" onclick="unit_add(this)" href="javascript:void(0);"><span class="ui-icon ui-icon-plus"></span>添加名单</a>
                                                        <a class="btn btn-blue ui-w" onclick="all_yes(this)" href="javascript:void(0);"><span class="ui-icon ui-icon-check"> </span>&nbsp;批量发布</a>
                                                        <label for="name" style="color: #666666;font-size: 16px;font-weight: normal;line-height: 34px;margin: 3px 0;margin-right: 25px;">状态:
                                                            <select id="select1" style="height: 34px;border:1px solid #e0e0e0;width: 150px; ">
                                                                <option value="0">全部</option>
                                                                <option value="1">已发布</option>
                                                                <option value="2">已下架</option>
                                                            </select>
                                                        </label>
                                                        <div class="search-form" style="margin-left:10px;width: 200px; ">
                                                            <input type="text" class="form-control" style="width: 200px;" id="name" placeholder="输入名称" />
                                                            <button type="button" id="submit" class="btn-search"><i class="fa fa-search"></i></button>
                                                        </div>
                                                    </div>
                                                    <div class="panel-body">
                                                        <table class="table table-hover table-striped table-bordered" data-page-size="12" data-filter="#filter">
                                                            <thead>
                                                                
                                                            </thead>
                                                            <tbody>
                                                            
                                                            </tbody>
                                                        </table>
                                                        <div class="pager" id="page" style="text-align: right;"></div> 
                                                     </div>
                                                </div>
                                            </div>
                                        </div>                                   
                                    </div>

                                </div>

                            </div>
                        </div>
                    </div>
                </div>

            </div><!--end row-->
            
            <!--end page content-->




        </section>
        <!--end main content-->


<!--Common plugins-->
<script src="_JS_/jquery.min.js"></script>
<script src="_JS_/jquery.base64.js"></script>
<script src="_JS_/jquery.cookie.js"></script>
<script src="_JS_/bootstrap.min.js"></script>
<script src="_JS_/jasny-bootstrap.min.js"></script>
<script src="_JS_/jquery.slimscroll.min.js"></script>
<script src="_JS_/jquery.nanoscroller.min.js"></script>
<script src="_JS_/metismenu.min.js"></script>
<script src="_JS_/float-custom.js"></script>
<script type="text/javascript" src="_JS_/layer/layer.js"></script>
<script type="text/javascript" src="_JS_/laypage/laypage.js"></script>
<script type="text/javascript" src="_JS_/laydata/laydate.js"></script>
<script type="text/javascript" src="_JS_/getMyDate.js"></script>
         <!-- Page-Level Scripts -->
        <script>
        
		
		$(function () {
			$("#page-title").html("企业评级管理");
			$("#type").val(1);
			postfile(1,1);
			
		})
		
		$(".list-inline li").on('click',function(){
			var text = $(this).attr('all');
			$("#type").val(text);
			postfile(1,text);
		})
		
		function postfile(page,type) {
			var status = $("#select1").val();
			var username = $(".search-form input").val();
			$.ajax({
				type: 'GET',
				url: "{:url('api/companys/companys_index')}",
				dataType: 'jsonp',
				jsonp: 'callback',
				data: {'page': page,'type':type, 'status': status, 'username': username},
				
				success: function (msg) {
					layer.closeAll();
					$("#companys").addClass("active").children("ul").addClass("in");
					$("#companys_index").addClass("choose");
					if (msg.code == 200) {
						var pages = Math.ceil(msg.data.count / 10);
						$(".table tbody").html("");
						$(".table thead").html("");
						if (msg.data.data.length > 0) {
							if(type == 1){
								var king = '';
								king += '<tr><th><input type="checkbox" id="role"></th><th>ID</th><th>企业名单</th><th>详细地址</th><th>企业介绍</th>'+
								'<th>网址</th><th>状态</th><th>操作</th></tr>';
								for (var i = 0; i < msg.data.data.length; i++) {
									var time = msg.data.data[i].time;
									ltime = getMyDate(time * 1000);

									var html = '<tr id="'+msg.data.data[i].id+'"><td><input class="checked" type="checkbox" name=""></td>'+
									'<td>'+msg.data.data[i].id+'</td><td>'+msg.data.data[i].name+'</td><td>'+msg.data.data[i].address+'</td>'+
									'<td width="200px;">'+msg.data.data[i].introduce+'</td>'+
									'<td><a href="http://'+msg.data.data[i].internet+'">'+msg.data.data[i].internet+'</a></td>';
									
									if(msg.data.data[i].status == 1){
										html+='<td class="td-status enable">上架</td>'+
										'<td class="buttons td-manage">'+
										'<a class="btn table-btn " onclick="news_down(this,'+msg.data.data[i].id+')" href="javascript:;" title="下架"><i class="fa fa-cloud-download"></i></a>';
									}else if(msg.data.data[i].status == 2){
										html+='<td class="td-status disable">下架</td>'+
										'<td class="buttons td-manage">'+
										'<a class="btn table-btn " onclick="news_up(this,'+msg.data.data[i].id+')"href="javascript:;" title="上架"><i class="fa fa-cloud-upload enable"></i></a>';
									}
									
									html+='<a class="btn table-btn" onclick="company_edit(this,'+msg.data.data[i].id+')" href="#" title="编辑"><i class="fa fa-pencil"></i></a>'+
                                    '<a class="btn table-btn" onclick="company_msg(this,'+msg.data.data[i].id+')" href="#" title="查看详情"><i class="fa fa-ellipsis-h"></i></a>'+
                                    '<a class="btn table-btn" onclick="news_del(this,'+msg.data.data[i].id+')" href="#" title="删除"><i class="fa fa-trash-o"></i></a>'+
                                    '</td></tr>';
									$(".table tbody").append(html);
								}
								$(".table thead").html(king);
								
							}else if(type == 2){
								var king = '';
								king += '<tr><th><input type="checkbox" id="role"></th><th>ID</th><th>机构名单</th><th>星级</th><th>联系方式</th>'+
								'<th>详细地址</th><th>机构介绍</th><th>状态</th><th>操作</th></tr>';
							
								for (var i = 0; i < msg.data.data.length; i++) {
									var time = msg.data.data[i].time;
									ltime = getMyDate(time * 1000);

									var html = '<tr id="'+msg.data.data[i].id+'"><td><input class="checked" type="checkbox" name=""></td>'+
									'<td>'+msg.data.data[i].id+'</td><td>'+msg.data.data[i].name+'</td><td>'+msg.data.data[i].star+'星</td>'+
									'<td width="200px;">'+msg.data.data[i].phone+'</td>'+
									'<td>'+msg.data.data[i].address+'</td><td>'+msg.data.data[i].introduce+'</td>';
									
									if(msg.data.data[i].status == 1){
									html+='<td class="td-status enable">上架</td>'+
									'<td class="buttons td-manage">'+
										'<a class="btn table-btn " onclick="news_down(this,'+msg.data.data[i].id+')" href="javascript:;" title="下架"><i class="fa fa-cloud-download"></i></a>';
									}else if(msg.data.data[i].status == 2){
									html+='<td class="td-status disable">下架</td>'+
									'<td class="buttons td-manage">'+
										'<a class="btn table-btn " onclick="news_up(this,'+msg.data.data[i].id+')" href="javascript:;" title="上架"><i class="fa fa-cloud-upload enable"></i></a>';
									}
									
									html +='<a class="btn table-btn" onclick="company_edit(this,'+msg.data.data[i].id+')" href="#" title="编辑"><i class="fa fa-pencil"></i></a>'+
                                    '<a class="btn table-btn" onclick="company_msg(this,'+msg.data.data[i].id+')" href="#" title="查看详情"><i class="fa fa-ellipsis-h"></i></a>'+
                                    '<a class="btn table-btn" onclick="news_del(this,'+msg.data.data[i].id+')" href="#" title="删除"><i class="fa fa-trash-o"></i></a>'+
                                    '</td></tr>';
									$(".table tbody").append(html);
								}
								$(".table thead").html(king);
							}else if(type == 3){
								var king = '';
								king += '<tr><th><input type="checkbox" id="role"></th><th>ID</th><th>代理人</th><th>机构名单</th><th>星级</th><th>资格证号</th><th>电子邮箱</th><th>专业</th>'+
								'<th>状态</th><th>操作</th></tr>';
								for (var i = 0; i < msg.data.data.length; i++) {
									var time = msg.data.data[i].time;
									ltime = getMyDate(time * 1000);

									var html = '<tr id="'+msg.data.data[i].id+'"><td><input class="checked" type="checkbox" name=""></td>'+
									'<td>'+msg.data.data[i].id+'</td><td>'+msg.data.data[i].username+'</td><td>'+msg.data.data[i].name+'</td>'+
									'<td>'+msg.data.data[i].star+'星</td>'+
									'<td>'+msg.data.data[i].certificate+'</td><td>'+msg.data.data[i].email+'</td>'+
									'<td>'+msg.data.data[i].major+'</td>';
									
									if(msg.data.data[i].status == 1){
									html+='<td class="td-status enable">上架</td>'+
									'<td class="buttons td-manage">'+
										'<a class="btn table-btn " onclick="news_down(this,'+msg.data.data[i].id+')" href="javascript:;" title="下架"><i class="fa fa-cloud-download"></i></a>';
									}else if(msg.data.data[i].status == 2){
									html+='<td class="td-status disable">下架</td>'+
									'<td class="buttons td-manage">'+
										'<a class="btn table-btn " onclick="news_up(this,'+msg.data.data[i].id+')" href="javascript:;" title="上架"><i class="fa fa-cloud-upload enable"></i></a>';
									}
									
									html +='<a class="btn table-btn" onclick="company_edit(this,'+msg.data.data[i].id+')" href="#" title="编辑"><i class="fa fa-pencil"></i></a>'+
                                    '<a class="btn table-btn" onclick="company_msg(this,'+msg.data.data[i].id+')" href="#" title="查看详情"><i class="fa fa-ellipsis-h"></i></a>'+
                                    '<a class="btn table-btn" onclick="news_del(this,'+msg.data.data[i].id+')" href="#" title="删除"><i class="fa fa-trash-o"></i></a>'+
                                    '</td></tr>';
									$(".table tbody").append(html);
								}
								$(".table thead").html(king);
							}
							 clickall();
							
						}
						//分页
						$(".table").attr("pages", page);
						laypage({
							cont: 'page',
							pages: pages,
							curr: page,
							jump: function (obj, first) {
								if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
									postfile(obj.curr,type);
								}
							}
						})
						
					} else {
						layer.msg('获取信息不成功!', {icon: 5, time: 2000});
					}
				}
			})
		}

		
		  // 搜索
		$('#submit').click(function () {
			var type = $("#type").val();
			postfile(1,type);
		})

		//回车键绑定搜索
		$(".search-form").keydown(function (event) {
			if (event.keyCode == 13) {
				var type = $("#type").val();
				postfile(1,type);
			}
		});

		// 状态查询
		$("#select1").change(function () {
			var type = $("#type").val();
			postfile(1,type);
		});
			
			
			
		

         /*全选*/
		 function clickall(){
			$("#role").change(function () {
				if ($(this).prop('checked')) {
					$("#role").prop('checked', true);
					$('.checked').prop('checked', true);
				} else {
					$("#role").prop('checked', false);
					$('.checked').prop('checked', false);
				}
			});
		}
		
        function all_yes(obj) {
            var arrs = [];
            $('tbody input:checked').parents('tr').each(function () {
                arrs.push($(this).attr('id'));
            });
            if (arrs.length == 0) {
                layer.msg('请选择需要上架的!', {icon: 1, time: 1000});
                return false;
            }
            var ids = arrs.join(",");
			news_up(obj,ids);
		}

		
        /*发布*/
        function news_up(obj,id){
			var page_id = $(".laypage_curr").html();
			var type = $("#type").val();
            layer.confirm('确认要发布吗？',function(index){
				 $.ajax({
					type: 'GET',
					url: "{:url('api/companys/companys_update')}",
					dataType: 'jsonp',
					jsonp: 'callback',
					data: {id: id,'status':1},
					success: function (msg) {
						if (msg.code == 200) {
							postfile(page_id,type);
						} else {
							layer.msg('受理失败', {icon: 5, time: 1000});
						}
					}
				});
				   
            });
        }
		
		

        /*删除*/
        function news_del(obj,id){
			var page_id = $(".laypage_curr").html();
			var type = $("#type").val();
            layer.confirm('确认要删除吗？',function(index){
				 $.ajax({
					type: 'GET',
					url: "{:url('api/companys/companys_update')}",
					dataType: 'jsonp',
					jsonp: 'callback',
					data: {id: id,'status':3},
					success: function (msg) {
						if (msg.code == 200) {
							postfile(page_id,type);
						} else {
							layer.msg('受理失败', {icon: 5, time: 1000});
						}
					}
				});
				   
            });
        }
		
        /*下架*/
        function news_down(obj,id){
			var page_id = $(".laypage_curr").html();
			var type = $("#type").val();
            layer.confirm('确认要下架吗？',function(index){
                //此处请求后台程序，下方是成功后的前台处理……
               $.ajax({
					type: 'GET',
					url: "{:url('api/companys/companys_update')}",
					dataType: 'jsonp',
					jsonp: 'callback',
					data: {id: id,'status':2},
					success: function (msg) {
						if (msg.code == 200) {
							postfile(page_id,type);
						} else {
							layer.msg('受理失败', {icon: 5, time: 1000});
						}
					}
				});
            });
    

		}
        /*企业添加*/
        function unit_add(obj){
			var type = $("#type").val();
            layer.open({
                type: 2,
                title: '添加',
                shadeClose: true,
                shade: 0.8,
                area: ['780px', '700px'],
                content: 'companys_add.html'+"#"+type
            });
        }
         /*企业编辑*/
        function company_edit(obj,id){
			var type = $("#type").val();
            layer.open({
                type: 2,
                title: '编辑',
                shadeClose: true,
                shade: 0.8,
                area: ['780px', '700px'],
                content: 'companys_edit.html'+"#"+id+"#"+type
            });
        }
         /*企业详情*/
        function company_msg(obj,id){
			var type = $("#type").val();
            layer.open({
                type: 2,
                title: '查看详情',
                shadeClose: true,
                shade: 0.8,
                area: ['780px', '700px'],
                content: 'companys_msg.html'+"#"+id + "#" + type
            });
        }
    </script>
    </body>
</html>